public class DemoTest01 {
  public static void main(String[] args) {
    // 获取Java虚拟机对象
    Runtime runtime = Runtime.getRuntime();

// 查询系统的空闲内存大小
    long freeMemory = runtime.freeMemory();
    long totalMemory = runtime.totalMemory();
    long maxMemory = runtime.maxMemory();

// 计算系统的空闲内存大小
    long systemFreeMemory = maxMemory - totalMemory + freeMemory;
    
    System.out.println("System free memory: " + systemFreeMemory / 1024 / 1024 + " bytes");
  }
}
